home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 July / macformat-026.iso / mac / Animation / Animation Assistant API / Mirror Events Example / MirrorEvents.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-27  |  3.2 KB  |  142 lines  |  [TEXT/KAHL]

  1. #if 0
  2. /****************************************************************************************
  3.  
  4.  
  5.         MirrorEvents.c
  6.  
  7.  
  8.         ©1993 Specular International Ltd.
  9.  
  10.         Revision History
  11.  
  12.         when        who            what & why
  13.         ==========    ==========    ======================================================
  14.         3/1/94        paul        new today
  15.  
  16. *****************************************************************************************/
  17. #endif
  18.  
  19. #include <SetUpA4.h>            /**  Generates code; should be first.  **/
  20.  
  21. #include <stddef.h>
  22. #include <Memory.h>
  23. #include "IASInterface.h"
  24.  
  25.  
  26. /**  Internally used routines.  **/
  27. unsigned long        manipulate_events(IASObjectInfoPtr  object_info);
  28.  
  29.  
  30.  
  31. /**
  32.  **  main()
  33.  **
  34.  **  Entry point for the plug-in animation assistant.
  35.  **
  36.  **  This is called first with the <kIAS_SetupStorage> message.
  37.  **  The <storage> param should be used to pass this info back.
  38.  **  The plugin must not depend on any global variables being valid
  39.  **  across calls. The contents of the <storage> must be a monolithic
  40.  **  application heap Handle.
  41.  **
  42.  **  It is then called with the <kIAS_GetParams> message,
  43.  **  which will allow the assistant to put up a dialog box asking
  44.  **  the user for parameters.
  45.  **
  46.  **  It is then called with the <kIAS_ManipulateEvents> message
  47.  **  with the info of the objects and their selected events in the <param> field.
  48.  **  It may be called repeatedly if there are a ton of events selected.
  49.  **
  50.  **  Finally, it is called with the <kIAS_CleanUpStorage> message.
  51.  **
  52.  **  The <param> field will be NULL for all but the kIAS_ManipulateEvents
  53.  **  messages.
  54.  **/
  55.  
  56. unsigned long        main(long  message, void  *param, Handle  *storage) {
  57.  
  58.     unsigned long            err;
  59.     
  60.     
  61.     /**
  62.      **  In case we use globals, set up A4 to refer to them.
  63.      **/
  64.      
  65.     RememberA0();
  66.     SetUpA4();
  67.     
  68.     err = 0;
  69.     switch(message)
  70.     {
  71.         case kIAS_SetupStorage:
  72.             break;                /**  No storage to set up.  **/
  73.             
  74.         case kIAS_GetParams:
  75.             break;                /**  No params to get.  **/
  76.  
  77.         case kIAS_ManipulateEvents:
  78.             err = manipulate_events((IASObjectInfoPtr) param);
  79.             break;
  80.             
  81.         case kIAS_CleanUpStorage:
  82.             break;                /**  Nothing to clean up.  **/
  83.     }
  84.     
  85.     RestoreA4();
  86.     return(err);
  87.     
  88. }  /**  End of main().  **/
  89.  
  90.  
  91.  
  92.  
  93. /**
  94.  **  manipulate_events()
  95.  **
  96.  **  Mirrors the animation in time represented by the selected eventmarks.
  97.  **/
  98.  
  99. unsigned long        manipulate_events(IASObjectInfoPtr  object_info)
  100. {
  101.     while(object_info != NULL)
  102.     {
  103.         IASEventPtr        event, last_event, pivot_event;
  104.         
  105.  
  106.         /**  Find the last eventmark.  **/
  107.         
  108.         for(event = object_info->selected_events; event->next != NULL; event = event->next);
  109.         
  110.         pivot_event = last_event = event;
  111.  
  112.         /**  Start with the one before the last.  **/
  113.             
  114.         event = event->prev;            
  115.         while(event != NULL)
  116.         {
  117.             IASEventPtr        new_event;
  118.                 
  119.                 
  120.             new_event = (IASEventPtr) NewPtr(sizeof(IASEvent));
  121.             if(new_event == NULL)
  122.                 return(MemError());
  123.                     
  124.             *new_event = *event;
  125.             new_event->time = pivot_event->time + (pivot_event->time - event->time);
  126.                 
  127.             new_event->id = 0;
  128.             new_event->next = NULL;
  129.             new_event->prev = last_event;
  130.             last_event->next = new_event;
  131.             last_event = new_event;
  132.             event = event->prev;            
  133.         }
  134.     
  135.         object_info = object_info->next;        
  136.     }
  137.  
  138.     return(0);
  139.     
  140. }  /**  End of manipulate_events().  **/
  141.  
  142.